package com.wnxy.admin.controller;

import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wnxy.admin.common.ResponseResult;
import com.wnxy.admin.dto.AlarmSettingDto;
import com.wnxy.admin.dto.PageResult;
import com.wnxy.admin.entity.ChargingRules;
import com.wnxy.admin.entity.MaintenancePersonnel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.wnxy.admin.entity.AlarmSettings;
import com.wnxy.admin.service.IAlarmSettingsService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author All
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/alarm-settings")
public class AlarmSettingsController {

    private final IAlarmSettingsService alarmSettingsServiceImpl;
    public AlarmSettingsController(IAlarmSettingsService alarmSettingsServiceImpl){
        this.alarmSettingsServiceImpl = alarmSettingsServiceImpl;
    }

    /*
     *  数据导出
     * */
    @GetMapping("/export")
    public void export(ModelMap map,
                       HttpServletRequest request,
                       HttpServletResponse response) {
        List<AlarmSettings> alarmSettingsList = alarmSettingsServiceImpl.list();
        ExportParams params = new ExportParams("报警设置列表", "报警设置列表", ExcelType.XSSF);
        map.put(NormalExcelConstants.DATA_LIST, alarmSettingsList);
        map.put(NormalExcelConstants.CLASS, AlarmSettings.class);
        map.put(NormalExcelConstants.PARAMS, params);
        map.put(NormalExcelConstants.FILE_NAME, "alarmSettingsList");
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
    }

    /*
    *  查询报警设置(ES分页)
    * */

    @GetMapping("/queryAlarmSetting")
    public ResponseResult queryAlarmSetting(@ModelAttribute AlarmSettingDto alarmSettingDto) {
        PageResult page = alarmSettingsServiceImpl.queryAlarmSetting(alarmSettingDto);
        return ResponseResult.ok(page);
    }

    /*
     *  编辑报警设置
     * */

    @PutMapping("/editAlarmSetting")
    public ResponseResult editAlarmSetting(@RequestBody AlarmSettings alarmSettings) {
        alarmSettingsServiceImpl.editAlarmSetting(alarmSettings);
        return ResponseResult.ok();
    }
}
